using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace Camalon.Drawing.Shapes
{
	/// <summary>
	/// Summary description for Bezier.
	/// </summary>
	[ToolboxItem(true)]
	public class Curve : VectorShape
	{

//		public Curve(System.ComponentModel.IContainer container):this()
//		{
//			///
//			/// Required for Windows.Forms Class Composition Designer support
//			///
//			container.Add(this);
//
//		}

		public Curve():base( Rectangle.FromLTRB(100,100,300,100))
		{

//			try
//			{
//				this.SuspendLayout();
//				base.MinSize		= new Size(10,5);
//				base.SetPoints(new AnchorPoint[]{ 
//											  new AnchorPoint( 0,0), 
//											  new AnchorPoint( 100,100),
//											  new AnchorPoint( 200,0)	
//										  });
//				base.Bounds			= Rectangle.FromLTRB(100,100,300,100);
//				base.DefaultMinSize = base.MinSize;
//				SetCanResize( false );
//			}
//			finally
//			{
//				this.ResumeLayout(true);
//			}

			base.SetPoints(new AnchorPoint[]{ 
												new AnchorPoint( 0,0), 
												new AnchorPoint( 100,100),
												new AnchorPoint( 200,0)	
											});

		}

		protected override GraphicsPath MakePath(Point[] points, bool closed )
		{
			GraphicsPath path = new GraphicsPath();

			try
			{
				if( points != null && points.Length >=3)
				{
					if( closed ) path.AddClosedCurve(points, _tension);
					else path.AddCurve(points, _tension);
				}
				else path.AddRectangle( base.Bounds );
				
			}
			catch( Exception e)
			{
				FileWatcher.WriteLine( e.StackTrace);
			}

			return path;
		}


		private float _tension = 1.0f;
		[Category("Style")]
		[DefaultValue(1.0f)]
		[TypeConverter( typeof( PercentConverter))]
		public float Tension
		{	
			get{ return _tension;}
			set
			{
				if( value < 0f) value = 0f;
				if( value == _tension) return;
				_tension = value;
				InvokeInternalChanged( true );
			}

		}


		protected override bool ValidatePoints(AnchorPoint[] points)
		{
			if( points == null || points.Length < 3 ) 
				throw new InvalidOperationException("Curve must contain at least 3 points");

			return true;
		}


	}
}
